🔧 Type the BuildEnvironment attributes used by SphinxNeedsData (Tier 2)#1729
Open
chrisjsewell wants to merge 1 commit into
Open
🔧 Type the BuildEnvironment attributes used by SphinxNeedsData (Tier 2)#1729chrisjsewell wants to merge 1 commit into
chrisjsewell wants to merge 1 commit into
Conversation
`SphinxNeedsData` stores its data as private attributes on the Sphinx `BuildEnvironment` (and `_needs_services` on the `Sphinx` app), which mypy cannot see — so the module carried a `disable_error_code = ["attr-defined", "no-any-return"]` override masking 45 errors. Declare those attributes on `TYPE_CHECKING`-only `BuildEnvironment`/`Sphinx` subclasses and `cast` `self.env` to the typed env in `__init__`. The accessor bodies are unchanged and the `cast` is a runtime no-op. This removes the last per-module `disable_error_code` override from the mypy config. Tier 2 of #1725. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016hgF7RDxmXvBnFhCkP3sNh
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1729 +/- ##
==========================================
+ Coverage 86.87% 89.42% +2.54%
==========================================
Files 56 74 +18
Lines 6532 10682 +4150
==========================================
+ Hits 5675 9552 +3877
- Misses 857 1130 +273
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tier 2 of #1725 (first item).
Problem
SphinxNeedsDatastashes all of its data as private attributes on the SphinxBuildEnvironment(e.g.env._needs_all_needs,env._needs_view,env._needs_schema, …) and_needs_serviceson theSphinxapp. mypy can't see these, sodata.pycarried an override masking the fallout:That override hid 45 errors (9 dynamic env attributes + 1 app attribute, each generating an
attr-definedand, where returned, ano-any-return).Fix
Declare the stashed attributes on
TYPE_CHECKING-only subclasses —_NeedsEnv(BuildEnvironment)and_NeedsApp(Sphinx)— andcastself.envto_NeedsEnvonce in__init__. Every accessor body is left untouched.TYPE_CHECKING, so there's no runtime footprint.cast("_NeedsEnv", env)is a runtime no-op — it returnsenvunchanged._NeedsEnvis-aBuildEnvironment, so nothing that consumes.envis affected.This removes the last per-module
disable_error_codeoverride from the mypy config —data.pyis now type-checked under full--strictwith no suppressions.Verification
mypy --strict— clean (78 files); all 45 previously-suppressed errors resolved with the override deletedruff check/ruff format— cleantest_basic_doc,test_api_usage,test_need_item_api,test_needpie_with_zero_needs,test_service_github,test_needs_builder(exercise need creation, views, services, umls, and the github app-attribute path)No changelog entry: internal type-checking change, no runtime behaviour difference (consistent with the Tier 1 PR #1726).
🤖 Generated with Claude Code
https://claude.ai/code/session_016hgF7RDxmXvBnFhCkP3sNh
Generated by Claude Code